<?php

namespace Salgamos\FrontendBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Salgamos\BackendBundle\Entity\Location;

class DefaultController extends Controller
{
    public function indexAction()
    {
        $em = $this->getDoctrine()->getEntityManager();
        $categories = $em->getRepository('SalgamosBackendBundle:Category')->findAll();
        return $this->render('SalgamosFrontendBundle:Default:index.html.twig', array('categories' => $categories));
    }
    
    public function locationAction($locationId)
    {
        $em = $this->getDoctrine()->getEntityManager();
        $location = $em->getRepository('SalgamosBackendBundle:Location')->findOneById($locationId);
        return $this->render('SalgamosFrontendBundle:Location:location.html.twig', array('location' => $location));
    }
    
    public function categoryAction($categoryAlias)
    {
        $em = $this->getDoctrine()->getEntityManager();
        $locations = $em->getRepository('SalgamosBackendBundle:Location')->findByCategoryAlias($categoryAlias);
        return $this->render('SalgamosFrontendBundle:Location:locationByCategory.html.twig', array('locations' => $locations));
    }
}
